package com.starlink.model.util;

import com.starlink.client.jd.request.base.Contact;
import com.starlink.model.dtomapper.AddressDtoMapper;
import com.starlink.model.domain.AddressDO;
import com.starlink.model.vo.AddressVO;
import com.google.common.collect.Lists;
import org.apache.commons.collections4.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhanghong
 */
public class AddressConvert {

    public static List<AddressVO> buildAddressVoList(List<AddressDO> addressDOList) {
        if (CollectionUtils.isEmpty(addressDOList)) {
            return Lists.newArrayList();
        }
        List<AddressVO> addressVOList = new ArrayList<>();
        for (AddressDO addressDO : addressDOList) {
            addressVOList.add(AddressDtoMapper.INSTANCE.do2VO(addressDO));
        }
        return addressVOList;
    }

    public static Contact buildContact(AddressDO addressDO) {
        return Contact.builder()
                .fullAddress(addressDO.getProvince() + addressDO.getCity() + addressDO.getArea() + addressDO.getDetail())
                .mobile(addressDO.getMobile())
                .name(addressDO.getReceiver())
                .build();
    }
}
